<?php 

Class appController extends Controller
{
	
	
    public function _initialize()
	{ 
		
		
		if (isset($_GET['code'])&&hy_check($_GET['code'],'un')=='#@_error')
		{
			hy_404();
		}
		
		/*开启手机功能*/
		//$cfg=Model('app')->get_cfg();
		$is_wap=C('wap_support');
		
		if($is_wap==1)
		{
			$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
			
			$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
			
			if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
			{
				$Loaction = '?g=mobile&a=index&m=index';
			
				if (!empty($Loaction))
				{
					header("Location: $Loaction\n");
			
					
				}
			
			}
		}	
		/*模板*/

		//配置会员信息
		$user['user_id']=session('user_id');
		$user['username']=session('username');
	
		$this -> assign('_U',$user);
        //注册函数 registerPlugin
       $this->registerPlugin("function","func",array('appController','tpl_model'));
    //    $this->assign_global();//栏目
      
	}
	
	// 注册一下
	
	public static function tpl_model($arg)
	{
		if(!empty($arg['model'])&&!empty($arg['action']))
			$item=Model($arg['model'])->$arg['action']($arg);
		//Ctrl('app')->assign($arg['item'], $item);
		
		return $item;
	}
	public function assign_global($config=array())
	{
		$cfg=Model('app')->get_cfg();
		$user=Model('user')->get_user(session('user_id'));
		if(isset($config['c']))
		{
			foreach($config['c'] as $k=>$v)
			{
				if(isset($cfg[$k]))
				{
					$cfg[$k]=$v;
					
				}
			}
		}
		C($cfg);
		
		C('lang',DEFAULT_LANG);
		//样式路径
		
		
		
		$path=SUBDIR."/Home/Webroot/".C('home_tpl').'/';	
		$this->set_tpl_dir('',C('home_tpl'));
		C('hy_path',$path);
		
		
	
		//配置
		
		$this -> assign('_GET',$_GET);
		$this -> assign('_C',C());
		$this -> assign('_L',Lang());
	}
	/**
	 *  是否已登录
	 * @access public
	 * @return void
	 */
	function check_member()
	{
		if(!Model('app')->is_member())
		{
			
			
			header('Location:/index.php?g=home&m=user&a=login');
			
		exit;
		}
		
	}
	
   
	public function get_ad($code)
	{
		$ad=Model('app')->get_ad($code);
		return $ad;
	}
	
}


